package service.temp.job.matching.poc.listingapi.feign;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.RequiredArgsConstructor;

/**
 * Interceptor for accessing api gateway.
 *
 * @author Chao Xiong (chxiong@coupang.com)
 */
@RequiredArgsConstructor
public class ApiGatewayInterceptor implements RequestInterceptor {
    private final String consumerToken;

    private static final String AUTHORIZATION_HEADER_NAME = "X-CAG-Authorization";
    private static final String AUTHORIZATION_VALUE_PREFIX = "AG_CONSUMER_TOKEN access-key=";

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(AUTHORIZATION_HEADER_NAME, AUTHORIZATION_VALUE_PREFIX + consumerToken);
    }
}
